import { type Ref, ref } from 'vue'
import { useEventBus } from './pubsub'
import type { EventBusListener } from './pubsub/types'

interface DarkModeReturnType {
  listenDarkModeChange: (listener: EventBusListener<'on' | 'off', any>) => void
  emitDarkMode: (event: 'on' | 'off', payload?: any) => void
  darkMode: Ref<boolean>
}

function f() {
  const t = useEventBus<'on' | 'off'>('dark mode')
  const darkMode = ref(false)
  let d: DarkModeReturnType = {
    listenDarkModeChange: t.on,
    emitDarkMode: t.emit,
    darkMode
  }
  return () => d
}

const useDarkMode = f()
export default useDarkMode
